package com.zh.spring.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 描述：com.zh.spring.controller
 *
 * @author 80002023
 *         2017/1/3.
 * @version 1.0
 * @since 1.8
 */
@RestController
public class ComputeCtrl {

    private final Logger logger = LoggerFactory.getLogger(getClass());

    @Autowired
    private DiscoveryClient client;

    @GetMapping("add")
    public String add(@RequestParam Integer a,
                      @RequestParam Integer b) {
        ServiceInstance instance = client.getLocalServiceInstance();
        Integer r = a + b;
        logger.info("/add, host: {}, service_id: {}, result: {}", instance.getHost(), instance.getServiceId(), r);
        return String.valueOf(r);
    }
}
